package com.xiaoluo.a22_filescan;

import android.util.Log;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @ Created on: 2020/11/1
 * @Author: LEGION XiaoLuo
 * @ Description:
 */
public class FileScanUtils {

    public static List<File> getFileByPath(String path) {
        ArrayList<File> list = new ArrayList<File>();
        getFiles(list, path);
        for (int i = 0; i < list.size(); i++) {
            String mPicName = list.get(i).getName();

            System.out.println("全明星:  " + mPicName);

            String substring = mPicName.substring(mPicName.lastIndexOf(".") + 1);

            System.out.println("后缀名：  " + substring);

            String string = mPicName.substring(0, mPicName.lastIndexOf("."));

            Log.e("eee", "文件名 ： " + string);

            CharSequence sequence = mPicName.subSequence(0, mPicName.lastIndexOf("."));

            Log.e("eee", "文件名 ： " + sequence);

        }

        return null;
    }


    private static void getFiles(ArrayList<File> list, String filePath) {
        File[] allFiles = new File(filePath).listFiles();
        if (allFiles != null) {
            for (int i = 0; i < allFiles.length; i++) {
                File file = allFiles[i];
                if (file.isFile()) {
                    list.add(file);
                }
            }
        }
    }
}
